loginController.$inject = ['userService', '$http', '$location'];

function loginController(userService, $http, $location) {
    var vm = this;
    vm.login = function() {
        vm.user = {
            name: vm.username,
            password: vm.password
        };
        console.log(vm.user)
        $http({
            url: "/api/admin/login",
            method: 'POST',
            data: vm.user
        }).then(function(response) {
            console.log(response)
            var data = response.data;
            console.log(data.token)
            if (data.token != null) {
                localStorage.setItem("username", vm.user.name);
                localStorage.setItem("token", data.token);
                $location.url('/manager/audit');
            } else
                $location.url('/login');

        })
    }

}

module.exports = loginController;